package com.dinner.struts.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.dinner.service.SellerService;
import com.dinner.util.PageHelper;

public class SellerPageAction extends Action {
	
	private SellerService service = null;

	/**
	 * @return the service
	 */
	public SellerService getService() {
		return service;
	}

	/**
	 * @param service the service to set
	 */
	public void setService(SellerService service) {
		this.service = service;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
			throws Exception {
		
		String pageNum = request.getParameter("pageNum");
		int page = pageNum == null ? 1 : Integer.parseInt(pageNum);
		
		PageHelper p = new PageHelper();
		p.setCurrentPage(page);
		
		List<com.dinner.model.Seller> list = service.getSellersByPage(p);
		request.getSession().setAttribute("SellerList", list);
		request.setAttribute("pageInfo", p);
		
		return mapping.getInputForward();
	}
	
	
}
